<!--
 * @Description: 学生店铺审核
 * @Author: Li Yujie
 * @Date: 2021/04/02
 * @Last Modified by: Li Yujie
 * @Last Modified time: 2021/04/02
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    学生入驻审核
                </div>
            </div>
            <!-- /header -->
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">公司名称</p>
                    <el-input
                        placeholder="请输入公司名称"
                        v-model="filterData.student_keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">审核状态</p>
                    <el-select
                        v-model="filterData.verify"
                        filterable
                        placeholder="全部"
                        size="medium"
                        style="width: 152px"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in statusList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <!--<div class="header-new-box">
                    <p class="header-new-box-title">提交时间</p>
                    <el-date-picker
                        v-model="dateTimeRange"
                        type="datetimerange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        size="medium"
                        style="width: 400px"
                        value-format="timestamp"
                    />
                </div>-->
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                </div>
            </div>
            <!--筛选-->

            <!-- table -->
            <el-table
                :data="tableData"
                height="100%"
                style="width: 100%;"
                ref="tempLateName"
                class="data-table"
                v-loading="tableLoading"
            >
                <el-table-column
                    label="序号"
                    align="center"
                    width="80"
                    type="index"
                />
                <el-table-column
                    prop="shop_title"
                    label="店铺名称"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    label="店铺类型"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div v-if="scope.row.shop_type === 1">个人店</div>
                        <div v-if="scope.row.shop_type === 2">个体工商户</div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="主营类目"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        主营类目
                    </template>
                </el-table-column>
                <el-table-column
                    prop="shop_address"
                    label="联系地址"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    label="资料类别"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        资料类别
                    </template>
                </el-table-column>
                <el-table-column
                    prop="legal_name"
                    label="法人姓名"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                    width="120"
                />
                <el-table-column
                    label="营业执照"
                    align="center"
                >
                    <template slot-scope="scope">
                        <img
                            src=""
                            class="table-image"
                            alt=""
                            @click="showPreview(scope.row.class_group_images)"
                        >
                    </template>
                </el-table-column>
                <el-table-column
                    label="手持身份证"
                    align="center"
                    width="140"
                >
                    <template slot-scope="scope">
                        <img
                            src=""
                            class="table-image"
                            alt=""
                            @click="showPreview(scope.row.class_group_images)"
                        >
                    </template>
                </el-table-column>
                <el-table-column
                    label="学生证"
                    align="center"
                >
                    <template slot-scope="scope">
                        <img
                            src=""
                            class="table-image"
                            alt=""
                            @click="showPreview(scope.row.class_group_images)"
                        >
                    </template>
                </el-table-column>
                <el-table-column
                    label="审核状态"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    width="140"
                >
                    <template slot-scope="scope">
                        <div class="status-wrapper">
                            <div
                                class="status-dot warning"
                                v-if="scope.row.verify === 0"
                            />
                            <div
                                v-else
                                :class="['status-dot',scope.row.verify === 1 ? 'success' : (scope.row.verify === -1 ? 'danger' : '')]"/>
                            <div class="status-name">{{ scope.row.verify | statusName }}</div>
                            <el-button
                                type="text"
                                style="margin-left: 6px; font-size: 12px"
                                v-if="scope.row.verify === -1"
                                @click="showReason(scope.row)"
                            >
                                (查看原因)
                            </el-button>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="提交时间"
                    align="center"
                    width="200"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.submit_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                    </template>
                </el-table-column>
                <el-table-column
                    label="操作"
                    align="left"
                    width="160"
                    fixed="right"
                >
                    <template slot-scope="scope">
                        <div class="option-btn-group">
                            <el-button
                                type="text"
                                size="medium"
                                :disabled="scope.row.verify !== 0"
                                @click="handleVerify(scope.row, 'pass')"
                            >
                                通过
                            </el-button>
                            <el-button
                                type="text"
                                size="medium"
                                :disabled="scope.row.verify !== 0"
                                @click="showRejectDialog(scope.row)"
                            >
                                不通过
                            </el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <!-- /table -->

            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
        <!-- 驳回弹窗 -->
        <reject-dialog
            ref="rejectDialog"
            :visible.sync="rejectDialog"
            :reason-detail="reasonDetail"
            :maxlength="100"
            @confirm="handleVerify(verifyRow, 'reject', $event)"
        />
        <!-- 图片预览 -->
        <!--<img-preview ref="preview"/>-->
        <!-- 图片预览 -->
        <el-image-viewer
            class="el-image-viewer--verify"
            v-if="showViewer"
            :url-list="previewImages"
            :initial-index="initialIndex"
            :mask-closable="false"
            :append-to-body="false"
            :on-close="() => { showViewer = false }"
        />
    </div>
</template>

<script>
import {back} from '@/mixin/back';
import ImgPreview from "@/components/common/img-preview";
import RejectDialog from "@/components/dialog/reject-dialog";
import ElImageViewer from 'element-ui/packages/image/src/image-viewer';

export default {
    name: 'StudentShopVerify',
    mixins: [back],
    components: {
        RejectDialog,
        ImgPreview,
        ElImageViewer
    },
    data() {
        return {
            filterData: {
                // 用户信息
                student_keyword: '',
                // 学校名称
                school_name: '',
                // 学院名称
                college_name: '',
                class_name: '',
                // 审核人
                verify_admin_true_name: '',
                // 审核状态
                verify: 99,
                // 报名时间
                start_time: '',
                end_time: ''
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            dateTimeRange: [],
            // 审核类型
            statusList: [
                {label: '全部', value: 99},
                {label: '待审核', value: 0},
                {label: '通过', value: 1},
                {label: '不通过', value: -1},
            ],
            rejectDialog: false,
            reasonDetail: '',
            verifyRow: {},
            // element图片预览
            previewImages: [],
            showViewer: false,
            initialIndex: 0
        };
    },
    computed: {},
    watch: {
        dateTimeRange(value) {
            this.filterData.start_time = value ? value[0] / 1000 : '';
            this.filterData.end_time = value ? value[1] / 1000 : '';
            this.getTableData(1);
        }
    },
    filters: {
        statusName(val) {
            switch (val) {
                case 0:
                    return '待审核';
                case 1:
                    return '通过';
                case -1:
                    return '不通过';
                default:
                    return '--';
            }
        },
    },

    mounted() {
        this.$store.commit('SET_HEADER', [{title: '官网'}, {title: '客户审核与合同'}, {title: '学生入驻审核'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },

    methods: {

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {

            this.tableLoading = true;
            let params = {...this.filterData};

            params.page_id = page || this.page.now_page;
            this.$post('/student/region_class_student_submit%5Cget_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 预览图片
         * @param   {String}    images      //单图预览
         * @param   {Array}     images      //多图预览
         * @param index
         */
        showPreview(images, index = 0) {
            this.previewImages = images;
            this.initialIndex = index;
            this.showViewer = true;
        },

        /**
         * 显示拒绝原因弹窗
         * @param row
         */
        showRejectDialog(row) {
            this.reasonDetail = '';
            this.verifyRow = row;
            this.rejectDialog = true;
        },

        /**
         * 审核通过或拒绝
         * @param row
         * @param action pass通过 reject拒绝
         * @param verify_fail_reason
         */
        handleVerify(row, action, verify_fail_reason = '') {
            if (!this.authResult.auth_verify) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }

            if (action === 'reject') {
                if (!verify_fail_reason) {
                    this.$message.warning('请填写审核驳回原因!');
                    return;
                }
                this.verifyRequest(row.id, -1, verify_fail_reason);
            } else {
                this.$confirm(`是否确定通过审核?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.verifyRequest(row.id, 1, '');
                });
            }
        },

        /**
         * 审核请求
         * @param id
         * @param verify
         * @param verify_fail_reason
         */
        verifyRequest(id, verify, verify_fail_reason) {
            let params = {
                id,
                verify,
                verify_fail_reason
            };

            this.$post('/student/region_class_student_submit%5Cverify', params, resp => {
                if (resp.code === 1) {
                    this.getTableData();
                    this.$notify({
                        title: '提示',
                        message: '操作成功',
                        type: 'success',
                        duration: 2000
                    });
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        type: 'warning',
                        duration: 2000
                    });
                }
            });
        },

        /**
         * 回显完成和未完成原因
         * @param row
         */
        showReason(row) {
            this.reasonDetail = row.verify_fail_reason;
            this.rejectDialog = true;
        },
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        padding: 24px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin-left: 12px;
                margin-bottom: 24px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*筛选*/

        .filter-view {
            margin-top: 12px;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 12px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
            }
        }

        // 表格
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }

            // 操作按钮
            .option-btn-group {
                .el-button {
                    margin-left: 0;
                    margin-right: 10px;
                }
            }
            .status-wrapper {
                display: flex;
                align-items: center;

                .status-dot {
                    width: 6px;
                    height: 6px;
                    border-radius: 50%;
                    margin-right: 5px;

                    &.success {
                        background: #4CD964;
                    }

                    &.danger {
                        background: #FF3030;
                    }

                    &.warning {
                        background: #FFA72D;
                    }

                    &.normal {
                        background: #C2C2C2;
                    }
                }
            }
        }

        .table-image {
            width: 57px;
            height: 57px;
            cursor: pointer;
        }

        /* 分页 */

        .pagination-wrapper {
            padding-top: 10px;

            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }

    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow: 0 1px 0 0 rgba(233, 233, 233, 1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;

        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }

        .el-icon-close:before {
            color: rgb(194, 194, 194);
            font-size: 17px;
            font-weight: bold;
        }

        .el-dialog__headerbtn {
            top: 14px;
        }
    }

    /deep/ .el-textarea__inner {
        resize: none;
    }

    .pic-list {
        display: flex;
        flex-wrap: wrap;
        margin-top: 12px;

        img {
            width: 100px;
            height: 100px;
            border-radius: 4px;
            border: 1px solid #F1F1F1;
            margin-right: 12px;
            margin-bottom: 12px;
            cursor: pointer;
        }
    }

    .verify-form {
        /deep/ .el-form-item {
            margin-bottom: 10px;
        }
    }
}
</style>

<style>
.el-image-viewer--verify {
    z-index: 2200!important;
}
</style>
